----------------------------------Spell Variables--------------------------------------
SPELL.m_iSpellID = 111032 -- Whatever value you want as long as it doesn't override any other spells' IDs.
SPELL.m_iRange = 240
SPELL.m_sName = "Wild Strikes"
SPELL.m_sToolTip =	[[Strike 3 times at the 
					target, each dealing 15
					damage per hit.
					Ignores armor.]]
SPELL.m_sIcon = "devin/blackbetty/spells/blademaster/sweeping_strike.png"
SPELL.m_iCoolDown = 5
SPELL.m_iManaCost = 50
SPELL.m_bRequiresTarget = true
SPELL.m_iSpellType = SPELLTYPE_SLOW
SPELL.m_bRecastWhileCasting = false

---------------------------------------------------------------------------------------

local range = 100

function SPELL:Cast( pl, target )
	
	if(target && target:IsValid() && target != pl ) then
		timer.Simple(1.2, function()
			pl:SetNWString("HoldType", "melee2") 
			pl:SetNWBool("Casting", false)
			pl:SetNWBool("Casted", false)
			pl.DoingCast = false
		end)
		pl:SetNWString("HoldType", "melee") 
		net.Start( "SendPlayerCast" )
		local SendTable = {1.2, self.m_sName, Color(155, 15, 15, 155)}
		net.WriteTable(SendTable)
		net.Send(pl)
		pl.DoingCast = true
		pl.CastWhileMoving = true
		if(pl:IsPlayer())then
			pl:DoAnimationEvent(ACT_HL2MP_GESTURE_RANGE_ATTACK_MELEE)
		else
			pl:RestartGesture(ACT_HL2MP_GESTURE_RANGE_ATTACK_MELEE)
		end
		pl:EmitSound("devin/blackbetty/weapons/Swipe.wav", 150, 100+math.random(-10,10))
		timer.Simple(0.1, function()
			if(target and pl:GetPos():Distance(target:GetPos()) < self.m_iRange)then
				self:Effect(pl, target)
				--self:ApplySpellMods(self, pl, target)
			end
		end)
		
		timer.Create(""..pl:EntIndex().."wildstrikes", 0.4, 2, function()
			if(pl:IsPlayer())then
				pl:DoAnimationEvent(ACT_HL2MP_GESTURE_RANGE_ATTACK_MELEE)
			else
				pl:RestartGesture(ACT_HL2MP_GESTURE_RANGE_ATTACK_MELEE)
			end
			pl:EmitSound("devin/blackbetty/weapons/Swipe.wav", 150, 100+math.random(-10,10))
			timer.Simple(0.1, function()
				if(target and pl:GetPos():Distance(target:GetPos()) < self.m_iRange)then
					self:Effect(pl, target)
					--self:ApplySpellMods(self, pl, target)
				end
			end)
		end)
	end
end

function SPELL:Effect(pl, target)

	local weapon = nil
	if(pl:IsPlayer())then
		weapon = pl:GetWeapon("weapon_all")
	else
		target = pl.Target
	end
	target:EmitSound("devin/blackbetty/weapons/Warrior_Heroic_Throw_Impact1.wav", 150, 100+math.random(-10,10))
	ParticleEffect( "pummel_hit", target:GetPos() + Vector(0, 0, 46) + (target:GetAngles():Forward()*6), Angle(0,0,0), pl )
	ParticleEffect( "player_blood", target:GetPos() + Vector(0, 0, 46) + (target:GetAngles():Forward()*6), Angle(0,0,0), pl )
	if(SERVER)then
		if(weapon)then
			self:DealDamage(15, 15, pl, target, DMG_SLASH)
		else
			self:DealDamage(pl.MinDamage*1, pl.MaxDamage*1, pl, target, DMG_SLASH)
		end
	end
end




